// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 信息 —————————————————————————————— //

  transInfo({ rootDto, ...obj }, { state: { INIT_ONE } }) {
    if (CORE.isEmpty(obj)) return {}

    if (obj.mapParent === 1 && !CORE.isEmpty(rootDto)) {
      obj.fileUrl = rootDto.fileUrl
      obj.mapName = rootDto.mapName
      obj.mapRate = rootDto.mapRate
      obj.pointTransJson = rootDto.pointTransJson
    }

    const [before, after] = obj.mapRate.split(':')
    const rateBefore = +before
    const rateAfter = +after

    const pointTransJson = obj.pointTransJson || '{}'
    const { Org2DPoints = [] } = JSON.parse(pointTransJson)
    const [x1, y1] = (Org2DPoints[0] || `${INIT_ONE.pointX1},${INIT_ONE.pointY1}`).split(',')
    const [x2, y2] = (Org2DPoints[1] || `${INIT_ONE.pointX2},${INIT_ONE.pointY2}`).split(',')
    const [x3, y3] = (Org2DPoints[2] || `${INIT_ONE.pointX3},${INIT_ONE.pointY3}`).split(',')

    return {
      ...obj,

      rateBefore,
      rateAfter,

      pointTransJson,

      pointX1: +x1, // 打点一的横向百分比
      pointY1: +y1, // 打点一的竖向百分比

      pointX2: +x2, // 打点二的横向百分比
      pointY2: +y2, // 打点二的竖向百分比

      pointX3: +x3, // 打点三的横向百分比
      pointY3: +y3, // 打点三的竖向百分比
    }
  },

  // —————————————————————————————— 增 —————————————————————————————— //

  transAdd(one) {
    const {
      pointX1: x1,
      pointY1: y1,
      pointX2: x2,
      pointY2: y2,
      pointX3: x3,
      pointY3: y3,
      areaId: MapId,
    } = one
    const Org2DPoints = [`${x1},${y1}`, `${x2},${y2}`, `${x3},${y3}`]
    return { ...one, pointTransJson: JSON.stringify({ Org2DPoints, MapId }) }
  },

  // —————————————————————————————— 改 —————————————————————————————— //

  transEditToAdd: true,
}
